﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLogic
{
    public static class ManufacturerTypeDataAccess
    {
        #region Methods
        public static ManufacturerType BindDataToManufacturerType(DataRow row)
        {
            return CodeTableDataAccess.BindRowToCodeTable<ManufacturerType>(row);
        }

        public static Guid Create(ManufacturerType manufacturerType)
        {
            Guid id = Guid.Empty;

            if (manufacturerType != null)
            {
                id = CodeTableDataAccess.Create<ManufacturerType>(StoredProcedures.USP_MANUFACTURERTYPECODE_CREATE, manufacturerType.Description);
            }

            return id;
        }

        public static void Delete(ManufacturerType manufacturerType)
        {
            Delete(manufacturerType.ID);
        }

        public static void Delete(Guid id)
        {
            List<Exception> exes = CodeTableDataAccess.Delete<ManufacturerType>(StoredProcedures.USP_MANUFACTURERTYPECODE_DELETE, id);

            if (exes != null && exes.Count > 0)
            {
                throw exes[0];
            }
        }

        public static DataTable GetAll()
        {
            return CodeTableDataAccess.GetAll(StoredProcedures.USP_MANUFACTURERTYPECODE_GETALL);
        }

        public static DataRow GetByID(Guid id)
        {
            return CodeTableDataAccess.GetByID(StoredProcedures.USP_MANUFACTURERTYPECODE_GETBYID, id);
        }

        public static void Update(ManufacturerType manufacturerType)
        {
            if (manufacturerType != null)
            {
                CodeTableDataAccess.Update<ManufacturerType>(StoredProcedures.USP_MANUFACTURERTYPECODE_UPDATE, manufacturerType.ID, manufacturerType.Description);
            }
        }
        #endregion
    }
}